package com.hi.hiparty.entity;

import java.text.ParseException;
import java.util.Date;

import com.hi.hiparty.util.TimeUtils;

import net.sf.json.JSONObject;

public class Post {

	public static interface PostContentType {
		public static final int Text = 0;
		public static final int Image = 1;
		public static final int Address = 2;
	}

	private String partyid;

	private String postid;

	private String userid;

	private String content;

	private int contentType;

	private Date createTime;

	public String getPartyid() {
		return partyid;
	}

	public void setPartyid(String partyid) {
		this.partyid = partyid;
	}

	public String getPostid() {
		return postid;
	}

	public void setPostid(String postid) {
		this.postid = postid;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getContentType() {
		return contentType;
	}

	public void setContentType(int contentType) {
		this.contentType = contentType;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}


	public JSONObject toJSON() {
		JSONObject postJson = new JSONObject();
		postJson.put("postid", postid);
		postJson.put("userid", userid);
		postJson.put("partyid", partyid);
		postJson.put("contentType", contentType);
		postJson.put("content", JSONObject.fromObject(content));
		postJson.put("create_time", TimeUtils.formatDateTime(createTime));
		return postJson;
	}

	public static Post fromJSON(JSONObject json) throws ParseException {
		Post post = new Post();
		post.setPartyid(json.getString("partyid"));
		post.setPostid(json.getString("postid"));
		post.setUserid(json.getString("userid"));
		post.setContentType(json.getInt("contentType"));
		post.setCreateTime(TimeUtils.parseDateTime(json.getString("create_time")));
		post.setContent(json.getJSONObject("content").toString());
		return post;
	}

}
